<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/rp/common/taglib.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>">
    
    <title>${ webpageTitle }</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	
	<script src="rp/scripts/boot.js" type="text/javascript"></script>
	
	<style type="text/css">
	   	
    </style>
    
    <script type="text/javascript" charset="utf-8" src="rp/scripts/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="rp/scripts/ueditor/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="rp/scripts/ueditor/lang/zh-cn/zh-cn.js"></script>
	
  </head>
  
  <body class="body-p5">
  	
  	<form id="form1" method="post">
  		<input name="id" class="mini-hidden" />
  		<table>
  			<tr>
  				<td>
  					<label>标题：</label>
  				</td>
  				<td>
  					<input id="textbox1" name="title" width="300" class="mini-textbox" required="true" emptyText="标题必填" />
  				</td>
  			</tr>
  			<tr>
  				<td>
  					<label>所属栏目：</label>
  				</td>
  				<td>
  					<input id="channelTreeSelect" name="channelId" class="mini-treeselect" style="width: 200px;" 
  							url="rp/infopub/channelMng/getChannels" 
                            textField="name" valueField="id" parentField="pid" checkRecursive="true"
                            emptyText="所属栏目必选"/>
  				</td>
  			</tr>
  			<tr>
  				<td valign="top">
  					<label>摘要：</label>
  				</td>
  				<td>
  					<input id="textarea1" name="summary" class="mini-textarea" width="500"/>
  				</td>
  			</tr>
  			<tr>
  				<td>
  					<label>标题图片：</label>
  				</td>
  				<td>
  					<input id="titleImg" name="imgPath" width="600" class="mini-textbox" 
  						emptyText="您可以通过内容编辑框的上传图片功能将图片上传（异步的），然后在将所上传图片的相对路径填入此处"/>
  					<a class="mini-button" onclick="previewTitleImg()"><i class="fa fa-eye fa-lg"></i> 预览图片</a>
  				</td>
  			</tr>
  			<tr>
  				<td valign="top">
  					<label>内容：</label>
  				</td>
  				<td>
  					<script id="editor" type="text/plain" style="width:800px;height:260px;">
						
					</script>
  				</td>
  			</tr>
  			<tr>
  				<td>
  					<label>激活显示：</label>
  				</td>
  				<td>
  					<input class="mini-combobox" style="width: 60px;" textField="text" 
  						name="enabled2" valueField="enabled2" value="0"
    					data="[{enabled2: '0', text: '禁用'}, {enabled2: '1', text: '激活'}]"
    					allowInput="false"/>
  				</td>
  			</tr>
  			<tr>
  				<td></td>
  				<td>
  					<a class="mini-button" onclick="submitForm()"><i class="fa fa-floppy-o fa-lg"></i> 保存</a>
  				</td>
  			</tr>
  		</table>
  	
  	</form>
  	
  	
  	
	<script type="text/javascript">
		var ue,form1;
	
		$(function(){
			mini.parse();
			ue = UE.getEditor("editor");
			form1 = new mini.Form("form1");
		});
		
		
		function getContent() {
	        return ue.getContent();
	    }
		
		function initData(_id){
			if(_id){
				rp_ajax("rp/infopub/articleMng/getArticleById", {articleId: _id}, function(text){
					//mini.alert(text.title);
					var o = mini.decode(text);
					form1.setData(o);
					form1.setChanged(false);
					ue.setContent(o.content);
				});
			}
		}
		
		function submitForm() {
			
			form1.validate();
            if (form1.isValid() == false) return;
			
            //校验是否已经选择栏目
            var treeSelect = mini.get("channelTreeSelect");
            if(!treeSelect.getValue()){
            	mini.alert("请选择文章所属栏目...");
            	//treeSelect.focus();
            	return;
            }
            
            //提交表单数据            
            var data = form1.getData();      //获取表单多个控件的数据
            var json = mini.encode(data);   //序列化成JSON
            //mini.alert(json);
            rp_ajax("rp/infopub/articleMng/saveArticle", {json: json, content: getContent()}, function(text){
            	if(text == "success"){
            		mini.alert("保存成功");
            	}
            });

        }

		//预览标题图片，根据填入的相对路径读取图片并使用窗口显示
        function previewTitleImg(){
	        var titleImg = mini.get("titleImg");
	        $.dialog({
		        title: "标题图片预览窗",
		        content: "<img src='"+titleImg.getValue()+"'/>"
		    });
        }
	</script>
  </body>
</html>
